//
//  BenchmarkConfig.m
//  GCDBenchmark
//
//  Created by Claude on 2025/10/13.
//

#import "BenchmarkConfig.h"

NSString * const kCommonAutoExit = @"kCommonAutoExit";

@implementation BenchmarkConfig

+ (instancetype)sharedConfig {
    static BenchmarkConfig *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[BenchmarkConfig alloc] init];
    });
    return instance;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self loadAutoExitPreference];
    }
    return self;
}

- (void)loadAutoExitPreference {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:kCommonAutoExit]) {
        _autoExitEnabled = [defaults boolForKey:kCommonAutoExit];
    } else {
        _autoExitEnabled = NO;
    }
}

- (void)saveAutoExitPreference {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:self.autoExitEnabled forKey:kCommonAutoExit];
    [defaults synchronize];
}

@end
